x11: Add gdk_x11_display_set_program_class
authorMatthias Clasen <mclasen@redhat.com>
Fri, 17 Nov 2017 04:18:58 +0000 (23:18 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 17 Nov 2017 04:21:06 +0000 (23:21 -0500)
The program class is a very X-specific concept.
There should be x11-backend api to deal with it.

docs/reference/gdk/gdk4-sections.txt
gdk/x11/gdkdisplay-x11.c
gdk/x11/gdkdisplay-x11.h
gdk/x11/gdkwindow-x11.c
gdk/x11/gdkx11display.h

index 97d1d25b75ff009309ad854d9914cd5d91a1a01a..ce11ad3c1b6bcdbd5682891ca6156c2db892a9f6 100644 (file)
@@ -902,6 +902,7 @@ gdk_x11_get_server_time
 gdk_x11_device_get_id
 gdk_x11_device_manager_lookup
 gdk_x11_display_open
+gdk_x11_display_set_program_class
 gdk_x11_display_get_user_time
 gdk_x11_display_broadcast_startup_message
 gdk_x11_display_get_startup_notification_id
index c89753a8510ca4dc021517ffb3eeaf7351f77363..cdca966220f157517289e0edc02dcb8b736fd343 100644 (file)
@@ -1663,7 +1663,7 @@ gdk_x11_display_open (const gchar *display_name)
 
   class_hint = XAllocClassHint();
   class_hint->res_name = (char *) g_get_prgname ();
-  class_hint->res_class = (char *)gdk_get_program_class ();
+  class_hint->res_class = (char *) g_get_prgname ();
 
   /* XmbSetWMProperties sets the RESOURCE_NAME environment variable
    * from argv[0], so we just synthesize an argument array here.
@@ -1760,6 +1760,35 @@ gdk_x11_display_open (const gchar *display_name)
   return display;
 }
 
+/**
+ * gdk_x11_display_set_program_class:
+ * @display: a #GdkDisplay
+ * @program_class: a string
+ *
+ * Sets the program class.
+ *
+ * The X11 backend uses the program class to set the class name part
+ * of the `WM_CLASS` property on toplevel windows; see the ICCCM.
+ *
+ * Since: 3.94
+ */
+void
+gdk_x11_display_set_program_class (GdkDisplay *display,
+                                   const char *program_class)
+{
+  GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
+  XClassHint *class_hint;
+
+  g_free (display_x11->program_class);
+  display_x11->program_class = g_strdup (program_class);
+
+  class_hint = XAllocClassHint();
+  class_hint->res_name = (char *) g_get_prgname ();
+  class_hint->res_class = (char *) program_class;
+  XSetClassHint (display_x11->xdisplay, display_x11->leader_window, class_hint);
+  XFree (class_hint);
+}
+
 /*
  * XLib internal connection handling
  */
@@ -2071,6 +2100,8 @@ gdk_x11_display_finalize (GObject *object)
       g_slice_free (GdkErrorTrap, trap);
     }
 
+  g_free (display_x11->program_class);
+
   G_OBJECT_CLASS (gdk_x11_display_parent_class)->finalize (object);
 }
 
index 60e6168b83490e793533be456c31201088cbfccc..73189e2524dd904b728b71b147ee907058a9f42f 100644 (file)
@@ -90,6 +90,7 @@ struct _GdkX11Display
   GHashTable *atom_to_virtual;
 
   /* Session Management leader window see ICCCM */
+  char *program_class;
   Window leader_window;
   GdkWindow *leader_gdk_window;
   gboolean leader_window_title_set;
index 84273f4019940db08d24deab1a68ff5adb7ca418..ef99753ccecb634c8d30e6d1c8bde417058622f7 100644 (file)
@@ -1000,7 +1000,7 @@ _gdk_x11_display_create_window_impl (GdkDisplay    *display,
 
       class_hint = XAllocClassHint ();
       class_hint->res_name = (char *) g_get_prgname ();
-      class_hint->res_class = (char *) gdk_get_program_class ();
+      class_hint->res_class = (char *) display_x11->program_class;
       XSetClassHint (xdisplay, impl->xid, class_hint);
       XFree (class_hint);
 
index 22035567a268672d6ecd6066a9f5d42e38a150aa..d43ebee7471aa4ca7c7186bd7b5ff975ad75a221 100644 (file)
@@ -76,6 +76,9 @@ const gchar * gdk_x11_display_get_startup_notification_id         (GdkDisplay *d
 GDK_AVAILABLE_IN_ALL
 void          gdk_x11_display_set_startup_notification_id         (GdkDisplay  *display,
                                                                    const gchar *startup_id);
+GDK_AVAILABLE_IN_3_94
+void          gdk_x11_display_set_program_class                   (GdkDisplay  *display,
+                                                                   const char  *program_class);
 
 GDK_AVAILABLE_IN_ALL
 void          gdk_x11_display_set_cursor_theme (GdkDisplay  *display,